package org.example.course.service.impl;

import org.example.course.common.DataGridView;
import org.example.course.common.utils.StringUtils;
import org.example.course.domain.Check;
import org.example.course.mapper.CheckMapper;
import org.example.course.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname CheckServiceImpl
 * @Description 考核环节
 * @Date 2020/5/8 21:28
 * @Created by
 */
@Service
public class CheckServiceImpl implements CheckService {

    @Autowired
    private CheckMapper mapper;

    @Override
    public boolean delete(String id) {
        int msg = mapper.deleteByPrimaryKey(Integer.valueOf(id));
        return msg > 0;
    }

    @Override
    public boolean create(Check check) {
        int msg = mapper.insert(check);
        return msg > 0;
    }

    @Override
    public boolean update(Check check) {
        int msg = mapper.updateByPrimaryKeySelective(check);
        return msg > 0;
    }

    @Override
    public DataGridView findCheckCols(String id) {
        List<Check> checks = mapper.findAllByCourseId(Integer.valueOf(id));
        return new DataGridView(checks);
    }

    @Override
    public boolean findCheckColsIsOk(String id) {
        List<Check> checks = mapper.findAllByCourseId(Integer.valueOf(id));
        for (Check check : checks) {
            String average = check.getAverage();
            if (StringUtils.isOneOfBlankEmptyNULL(average)) {
                return false;
            }
        }
        return true;
    }


}
